﻿using System;
using System.Collections.Generic;
using System.Text;
using SalePartial.IDAL;
using DataLayerAgent;
using System.Data.SqlClient;
using System.Data;
using SalePartial.Utility;
using SalePartial.Model;

namespace SalePartial.SQLServerDAL
{
    class XPCompany : IXPCompany
    {
        // Methods
        //<DataObjectMethod(DataObjectMethodType.Delete)> _
        public int Delete(Guid CompanyID)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("CompanyID", CompanyID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyDelete]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Delete)> _
        public int DeleteByUserID(Guid UserID)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("UserID", UserID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPCompaniesDeleteByUserID]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Delete)> _
        public  int DeleteDynamic(string v_whereCondition)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("WhereCondition", v_whereCondition) };
            return dbo.RunProcedure("[dbo].[xunpan_XPCompaniesDeleteDynamic]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Insert)> _
        public int Insert(XPCompanyInfo info)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] {
			new SqlParameter("CompanyID", info.CompanyID),
			new SqlParameter("UserID", info.UserID),
			new SqlParameter("CompanyName", info.CompanyName),
			new SqlParameter("CompanyAliasName", info.CompanyAliasName),
			new SqlParameter("Industry", info.Industry),
			new SqlParameter("WebSite",info.WebSite),
			new SqlParameter("OfficePhone", info.OfficePhone),
			new SqlParameter("OfficePhoneValidate", info.OfficePhoneValidate),
			new SqlParameter("IsOfficePhonePublic", info.IsOfficePhonePublic),
			new SqlParameter("CellPhone", info.CellPhone),
			new SqlParameter("CellPhoneValidate", info.CellPhoneValidate),
			new SqlParameter("IsCellPhonePublic", info.IsCellPhonePublic),
			new SqlParameter("Fax", info.Fax),
			new SqlParameter("FaxValidate", info.FaxValidate),
			new SqlParameter("IsFaxPublic", info.IsFaxPublic),
			new SqlParameter("Country", info.Country),
			new SqlParameter("Province", info.Province),
			new SqlParameter("City", info.City),
			new SqlParameter("Address", info.Address),
			new SqlParameter("PostCode", info.PostCode),
			new SqlParameter("CompanyOwner", info.CompanyOwner),
			new SqlParameter("CompanyContact", info.CompanyContact),
			new SqlParameter("CompanyEmail", info.CompanyEmail),
			new SqlParameter("IsEmailPublic", info.IsEmailPublic),
			new SqlParameter("LicenseCertID", info.LicenseCertID),
			new SqlParameter("Photo", info.Photo),
			new SqlParameter("Logo",info.Logo),
			new SqlParameter("Description",info.Description),
			new SqlParameter("Monetary",info. Monetary),
			new SqlParameter("Scale", info.Scale),
			new SqlParameter("Fund", info.Fund),
			new SqlParameter("Software", info.Software),
			new SqlParameter("Technology", info.Technology),
			new SqlParameter("Product", info.Product),
			new SqlParameter("CreateDate", info.CreateDate),
			new SqlParameter("IsApproved", info.IsApproved),
			new SqlParameter("IsLockedOut", info.IsLockedOut),
			new SqlParameter("VendorModerateDate", info.VendorModerateDate),
			new SqlParameter("VendorModerateUser", info.VendorModerateUser),
			new SqlParameter("VendorModerateStatus", info.VendorModerateStatus),
			new SqlParameter("BuyerModerateDate", info.BuyerModerateDate),
			new SqlParameter("BuyerModerateUser", info.BuyerModerateUser),
			new SqlParameter("BuyerModerateStatus",info.BuyerModerateStatus),
			new SqlParameter("LastModerateDate",info.LastModerateDate),
			new SqlParameter("ModerateUser", info.ModerateUser),
			new SqlParameter("ModerateCount", info.ModerateCount),
			new SqlParameter("ModerateComment",info.ModerateComment)
		};
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyInsert]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public DataSet SelectAll()
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[0];
            return dbo.RunProcedure("[dbo].[xunpan_XPCompaniesSelectAll]", parameters, "XPCompany_All");
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public DataSet SelectByUserID(Guid UserID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("UserID", UserID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPCompaniesSelectByUserID]", parameters, "XPCompany_ByUserID");
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public DataSet SelectDynamic(string v_whereCondition, string v_orderByExpression)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] {
			new SqlParameter("WhereCondition", v_whereCondition),
			new SqlParameter("OrderByExpression", v_orderByExpression)
		};
            return dbo.RunProcedure("[dbo].[xunpan_XPCompaniesSelectDynamic]", parameters, "XPCompany_Dynamic");
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public DataSet SelectPaged()
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[0];
            return dbo.RunProcedure("[dbo].[xunpan_XPCompaniesSelectPaged]", parameters, "XPCompany_Paged");
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public SqlDataReader SelectReader(Guid CompanyID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("CompanyID", CompanyID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanySelect]", parameters);
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public SqlDataReader SelectReaderByUserID(Guid UserID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("UserID", UserID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPCompaniesSelectByUserID]", parameters);
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public DataSet SelectSingle(Guid CompanyID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("CompanyID", CompanyID) };
            DataSet ds = dbo.RunProcedure("[dbo].[xunpan_XPCompanySelect]", parameters, "XPCompany_Single");
            DataTable dt = ds.Tables["XPCompany_Single"];
            return ds;
        }

        //<DataObjectMethod(DataObjectMethodType.Update)> _
        public int Update(XPCompanyInfo info)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] {
			new SqlParameter("CompanyID", info.CompanyID),
			new SqlParameter("UserID", info.UserID),
			new SqlParameter("CompanyName", info.CompanyName),
			new SqlParameter("CompanyAliasName", info.CompanyAliasName),
			new SqlParameter("Industry", info.Industry),
			new SqlParameter("WebSite", info.WebSite),
			new SqlParameter("OfficePhone", info.OfficePhone),
			new SqlParameter("OfficePhoneValidate",info.OfficePhoneValidate),
			new SqlParameter("IsOfficePhonePublic", info.IsOfficePhonePublic),
			new SqlParameter("CellPhone", info.CellPhone),
			new SqlParameter("CellPhoneValidate", info.CellPhoneValidate),
			new SqlParameter("IsCellPhonePublic", info.IsCellPhonePublic),
			new SqlParameter("Fax", info.Fax),
			new SqlParameter("FaxValidate",info.FaxValidate),
			new SqlParameter("IsFaxPublic", info.IsFaxPublic),
			new SqlParameter("Country", info.Country),
			new SqlParameter("Province", info.Province),
			new SqlParameter("City", info.City),
			new SqlParameter("Address", info.Address),
			new SqlParameter("PostCode", info.PostCode),
			new SqlParameter("CompanyOwner",info.CompanyOwner),
			new SqlParameter("CompanyContact", info.CompanyContact),
			new SqlParameter("CompanyEmail", info.CompanyEmail),
			new SqlParameter("IsEmailPublic", info.IsEmailPublic),
			new SqlParameter("LicenseCertID",info.LicenseCertID),
			new SqlParameter("Photo", info.Photo),
			new SqlParameter("Logo", info.Logo),
			new SqlParameter("Description",info.Description),
			new SqlParameter("Monetary", info.Monetary),
			new SqlParameter("Scale", info.Scale),
			new SqlParameter("Fund", info.Fund),
			new SqlParameter("Software", info.Software),
			new SqlParameter("Technology", info.Technology),
			new SqlParameter("Product", info.Product),
			new SqlParameter("CreateDate", info.CreateDate),
			new SqlParameter("IsApproved", info.IsApproved),
			new SqlParameter("IsLockedOut", info.IsLockedOut),
			new SqlParameter("VendorModerateDate", info.VendorModerateDate),
			new SqlParameter("VendorModerateUser", info.VendorModerateUser),
			new SqlParameter("VendorModerateStatus", info.VendorModerateStatus),
			new SqlParameter("BuyerModerateDate", info.BuyerModerateDate),
			new SqlParameter("BuyerModerateUser", info.BuyerModerateUser),
			new SqlParameter("BuyerModerateStatus", info.BuyerModerateStatus),
			new SqlParameter("LastModerateDate", info.LastModerateDate),
			new SqlParameter("ModerateUser", info.ModerateUser),
			new SqlParameter("ModerateCount", info.ModerateCount),
			new SqlParameter("ModerateComment", info.ModerateComment)
		};
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyUpdate]", parameters, RowsAffected);
        }

    }
}
